package com.mtf.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Description: mtf_order
 * @Author: jeecg-boot
 * @Date:   2023-11-02
 * @Version: V1.0
 */
@Data
@TableName("mtf_order")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="mtf_order对象", description="mtf_order")
@AllArgsConstructor
@NoArgsConstructor
public class MtfOrder implements Serializable, Delayed {
    private static final long serialVersionUID = 1L;

	/**编号*/
	@TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "编号")
    private Integer id;
	/**标识*/
    @ApiModelProperty(value = "标识")
    private String identity;
	/**订单名称*/
    @ApiModelProperty(value = "订单名称")
    private String orderName;
	/**订单编号*/
    @ApiModelProperty(value = "订单编号")
    private String orderCode;
	/**数量*/
    @ApiModelProperty(value = "数量")
    private Integer num;
	/**订单创建时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "订单创建时间")
    private Date createTime;
	/**订单创建人id*/
    @ApiModelProperty(value = "订单创建人id")
    private String createBy;
	/**订单创建人*/
    @ApiModelProperty(value = "订单创建人")
    private String createUsername;
	/**订单修改时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "订单修改时间")
    private Date updateTime;
	/**订单修改人id*/
    @ApiModelProperty(value = "订单修改人id")
    private String updateBy;
	/**订单修改人*/
    @ApiModelProperty(value = "订单修改人")
    private String updateUsername;
	/**是否有效 0有效，1无效*/
    @ApiModelProperty(value = "是否有效 0有效，1无效")
    private Integer status;
	/**是否删除 0未删除，1已删除*/
    @ApiModelProperty(value = "是否删除 0未删除，1已删除")
    @TableLogic
    private Integer delFlag;
	/**商品id*/
    @ApiModelProperty(value = "商品id")
    private String productIdentity;
    /**版本号*/
    @TableField(exist = false)
    @ApiModelProperty(value = "版本号")
    private String version;
    /**时间戳*/
    @TableField(exist = false)
    @ApiModelProperty(value = "时间戳")
    private String timestamp;
    @TableField(exist = false)
    private List<MtfOrderDetail> orderDetailList;
    @TableField(exist = false)
    private Long startTimeStamp;

    public MtfOrder(Integer id, String orderName, Integer num) {
        this.id = id;
        this.orderName = orderName;
        this.num = num;
    }

    public MtfOrder(String orderName, Integer num) {
        this.orderName = orderName;
        this.num = num;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        long diff = startTimeStamp - System.currentTimeMillis();
        return unit.convert(diff, TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return (int) (this.startTimeStamp - ((MtfOrder) o).startTimeStamp);
    }
}
